﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Tenmah.BusinessLogic.BusinessEntities;
using Tenmah.BusinessLogic;

namespace Tenmah.Web.Administrator
{
    public partial class EditUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int? UserId = Convert.ToInt32(Request.Params["userId"]);
            if (UserId != 0 && UserId != null)
            {
                RoleCollection rcol = new RoleCollection();
                rcol.Add(new Role(1, "adminstrator"));
                rcol.Add(new Role(2, "teacher"));
                User user = new User(1, "DEin", rcol);
                UserCollection ucol = new UserCollection();
                ucol.Add(user);
                UserFormView.DataSource = ucol;
                DataBind();
                FillUserRolesCheckBoxList(ucol[0].UserRoles);                
            }
            DataBind();
        }
        protected void AddUserButton_Click(object sender, EventArgs e)
        {

        }
        protected void DeleteUserButton_Click(object sender, EventArgs e)
        {

        }
        protected void SaveUserButton_Click(object sender, EventArgs e)
        {

        }
        public void FillUserRolesCheckBoxList(RoleCollection rc)
        {
            CheckBoxList UserRolesCheckBoxList = new CheckBoxList();
            UserRolesCheckBoxList = (CheckBoxList)UserFormView.FindControl("UserRolesCheckBoxList");
            foreach (Role r in rc)
            {                
                UserRolesCheckBoxList.Items.FindByValue(r.ID.ToString()).Selected = true;                
            }
        }
    }
}
